package framework.mocks
{
    import framework.remote.RemoteCollection;
    
    import mx.collections.ArrayCollection;
    import mx.rpc.AbstractOperation;
    import mx.rpc.AbstractService;

    public class MockRemoteObject extends AbstractService
    {
        public function MockRemoteObject()
        {
        }

        public function addMockOperation(name:String, func:Function, delay:Number = 200):void
        {
            var op:AbstractOperation = new MockOperation(func, delay, this, name);
            operations[name] = op;
        }

        override public function getOperation(name:String):AbstractOperation
        {
        	var op:AbstractOperation = super.getOperation(name);
            if (!op)
            {
            	addMockOperation(name, defaultMockFunction,50);
            	op = super.getOperation(name);
            }
            return op;
        }
        
        private function defaultMockFunction(...args):ArrayCollection
        {
        	trace("defaultMockFunction() called with args "+args);
        	return new RemoteCollection(new function():ArrayCollection {return new ArrayCollection()},[]);	
        }
    }
}